package com.beyond.market.record.controller;

import com.beyond.market.record.domain.Record;
import com.beyond.market.record.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;

@Controller
public class RecordController1 {
    @Autowired
    private RecordService recordService;
    @RequestMapping("/save")
    public String c(){
        return "save";
    }
    @RequestMapping ("/getId")
    public String b(){
        return "/getId";
    }
    @RequestMapping("/saveRecord")
    public String save(Integer orderDetailsId, Integer userId){
        Record record = new Record();
        record.setOrderDetailsId(orderDetailsId);
        record.setUserId(userId);
        try {
            Integer re = recordService.save(record);
            if (re == 1){
                return "ok";
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
       return null;

    }
    @RequestMapping("/removeRecord")
    public String remove(Integer recordId) {
        try {

            Integer remove = recordService.remove(recordId);
            if( remove == 1){
                return "a";
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getByPrimaryKey")
    public String getRecordByPrimaryKey(Integer id, ModelMap mm){
        try {
            Record r = recordService.getRecordByPrimaryKey(id);
            mm.put("r",r);
            return "/getById";
        } catch (SQLException e) {
        }
        return null;
    }
}
